<!--基础 Styles-->
<link href="assets/css/bootstrap.min.css" rel="stylesheet"/>
<link href="assets/css/font-awesome.min.css" rel="stylesheet"/>
<!--自定义 styles-->
<link id="beyond-link" href="assets/css/beyond.min.css" rel="stylesheet" type="text/css"/>
<script src="${ctx}/assets/js/fuelux/treeview/tree-custom.min.js"></script>
<#--数据库表属性结构面板-->
<div id="databaseTableTree" class="tree  tree-solid-line">
    <div class="tree-folder" style="display: none;">
        <div class="tree-folder-header">
            <i class="fa fa-folder fa-table green"></i>
            <div class="tree-folder-name"></div>
        </div>
        <div class="tree-folder-content"></div>
        <div class="tree-loader" style="display: none;"></div>
    </div>
    <div class="tree-item" style="display: none;">
        <i class="tree-dot"></i>
        <div class="tree-item-name"></div>
    </div>
</div>
<script type="text/javascript">
    <!--
    var AjaxDataSourceTree = function (options) {
        this._data = options.data;
        this._delay = options.delay;
        this._loadData = options.loadData;
        this._isInit = false;
    };
    AjaxDataSourceTree.prototype = {
        data: function (options, callback) {
            if (options.params && options.params.uuid) {
                console.log(options.params.uuid);
            }
            var self = this;
            if (self._isInit && self._loadData
                && (typeof self._loadData === "function")) {
                self._loadData(options, function (data) {
                    if (!data) {
                        data = [];
                    }
                    callback({
                        data: data
                    });
                });
            } else {
                setTimeout(function () {
                    var data = $.extend(true, [], self._data);
                    var childrenData = options.data;
                    if (childrenData) {
                        if (childrenData.length > 0) {
                            data = childrenData;
                        } else {
                            data = [];
                        }
                    }
                    callback({
                        data: data
                    });
                    self._isInit = true;
                }, this._delay);
            }
        }
    };
    /**
     * 延迟加载数据库表
     */
    function loadAjaxTree(treeId, tableName, catalog, setDataCallback) {
        var url = "${ctx}/preserve/database/getAllTable.do";
        if (!tableName) {
            tableName = "";
        }
        var params = {
            catalog: catalog,
            tableName: tableName
        };
        ajaxRequest(url, params, function (data) {
            if (data.resCode == "200") {
                var treeData = eval("(" + data.data + ")");
                console.log(treeData);
                if (setDataCallback && (typeof setDataCallback === "function")) {
                    setDataCallback(treeData);
                } else {
                    var databaseTableTreeAjaxDataSourceTree = new AjaxDataSourceTree({
                        data: treeData,
                        delay: 100,
                        loadData: function (option, callback) {
                            var tableName = "", catalog = "";
                            console.log(option.params);
                            if (option.params && option.params.name && option.params.catalog) {
                                tableName = option.params.name;
                                catalog = option.params.catalog;
                            }
                            loadAjaxTree(treeId, tableName, catalog, callback);
                        }
                    });
                    $("#" + treeId).tree({
                        cacheItems: true,
                        selectable: false,
                        dataSource: databaseTableTreeAjaxDataSourceTree,
                        loadingHTML: '<div class="tree-loading"><i class="fa fa-rotate-right fa-spin"></i></div>'
                    });
                }
            } else {
                ajaxError(data.resMsg);
            }
        },
        function (XMLHttpRequest, textStatus, errorThrown) {
            ajaxError(errorThrown);
        }, "GET", "JSON");
    }
    loadAjaxTree("databaseTableTree");
    //-->
</script>